//
//  XLMineBaseTableViewCell.m
//  Mine
//
//  Created by 于鹏 on 2017/8/25.
//  Copyright © 2017年 YIVIEW. All rights reserved.
//

#import "XLMineBaseTableViewCell.h"
#import "XLMineBaseCellModel.h"
//#import <Masonry.h>
#import "Masonry.h"

@interface XLMineBaseTableViewCell ()


@end

@implementation XLMineBaseTableViewCell

- (void)setupUI {
//    [super setupUI];
    
    //添加顶部分割线
    UIView *topLine = [[UIView alloc]init];
    UIColor *color = XL_KSeparateColor;
    [topLine setBackgroundColor:color];
    [self.contentView addSubview:topLine];
    self.topLine = topLine;
    
    //添加底部分割线
    UIView *bottomLine = [[UIView alloc]init];
    [bottomLine setBackgroundColor:color];
    [self.contentView addSubview:bottomLine];
    self.bottomLine = bottomLine;
    
    //添加右边剪头
    UIImageView *arrow = [[UIImageView alloc] init];
    [self.contentView addSubview:arrow];
    self.arrow = arrow;
    
    //添加标题
    XLCellLabel *titleLabel = [[XLCellLabel alloc]init];
    titleLabel.tintColor = XL_KTitleColor;
    titleLabel.font = XL_KTitleFont;
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    [self addConstraints];
}

- (void)layoutSubviews {
    [super layoutSubviews];
//    [self addConstraints];//设置图片约束
}
- (void)addConstraints {
    [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.contentView).offset(0);
        make.height.mas_equalTo(XL_KSeparateHeight);
    }];
    [self.arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-XL_KControlRightOffset);
        make.width.mas_equalTo(XL_KArrowWidth);
        make.height.mas_equalTo(XL_KArrowHeight);
        make.centerY.equalTo(self.contentView.mas_centerY).offset(0);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(XL_KCellMargin);
        make.centerY.equalTo(self.contentView.mas_centerY).offset(0);
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(self.contentView).offset(0);
        make.left.equalTo(self.contentView).offset(XL_KCellMargin);
        make.height.mas_equalTo(XL_KSeparateHeight);
    }];

}

#pragma mark - Override
+ (XLBaseTableViewCell *)cellWithIdentifier:(NSString *)cellIdentifier tableView:(UITableView *)tableView {
    XLMineBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[XLMineBaseTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (void)setupDataModel:(XLBaseCellModel *)model {
    [super setupDataModel:model];
    XLMineBaseCellModel *mineModel = (XLMineBaseCellModel *)model;
//    self.textLabel.text = mineModel.title;
//    self.textLabel.textColor = mineModel.titleColor;
//    self.textLabel.font = mineModel.titleFont;
    self.titleLabel.text = mineModel.title;
    self.titleLabel.textColor = mineModel.titleColor;
    self.titleLabel.font = mineModel.titleFont;
    self.selectionStyle = mineModel.selectionStyle;
    self.arrow.image = mineModel.arrowImage;
    self.arrow.hidden = !mineModel.isShowArrow;
    [self.bottomLine mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(mineModel.isTopGrid ? 0 : XL_KCellMargin);
    }];
}




@end
